//
//  FRQAppOpenViewController.m
//  FRQBluetoothKit_Example
//
//  Created by admin on 2023/11/15.
//  Copyright © 2023 xuchunhai. All rights reserved.
//

#import "FRQAppOpenViewController.h"
#import "TabbarViewController.h"
#import "FRQLoginViewController.h"
@interface FRQAppOpenViewController ()

@end

@implementation FRQAppOpenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //初始化蓝牙
    [BlueManager shareInstance];
//    [SkToast SkToastShow:@"发现读的特征"];
    NSLog(@"用户的token%@",KuserToken);
    if(KuserToken.length>0){
        [self auth];
    }else{
        FRQLoginViewController *view=[[FRQLoginViewController alloc] init];
        BaseNavoigationViewController *nav=[[BaseNavoigationViewController alloc] initWithRootViewController:view];
        [[[UIApplication sharedApplication] delegate] window].rootViewController=nav;
    }
}
- (void)auth {
//    每次启动app调用该接口
    NSString *jPushId=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"jPushId"]];
    if(jPushId.length<10){
        jPushId=@"";
    }
    NSDictionary *dic=@{
        @"jPushId":jPushId
    };
    
    [skNetTools skPOSTWithURL:[NSString stringWithFormat:@"%@%@",skURL,@"app/user/auth"] parameters:dic cachePolicy:0 callback:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        NSLog(@"数据=%@",responseObject);
        skNetModel *model=responseObject;
        [loginModel mj_objectWithKeyValues:model.data];
        if(model.code==200){
            NSString *token=[model.data objectForKey:@"token"];
            [skNetTools sksetToken:token];
            
            NSDictionary *dic=[model.data objectForKey:@"myDevice"];
            
            if(![dic isKindOfClass:[NSNull class]]){
                [skNetTools sksetMyDevice:dic];
                CustomTabBarViewController *rootView=[[CustomTabBarViewController alloc] init];
                [[[UIApplication sharedApplication] delegate] window].rootViewController=rootView;
            }else{
                FRQLoginViewController *view=[[FRQLoginViewController alloc] init];
                BaseNavoigationViewController *nav=[[BaseNavoigationViewController alloc] initWithRootViewController:view];
                [[[UIApplication sharedApplication] delegate] window].rootViewController=nav;
            }
            
        }else{
            FRQLoginViewController *view=[[FRQLoginViewController alloc] init];
            BaseNavoigationViewController *nav=[[BaseNavoigationViewController alloc] initWithRootViewController:view];
            [[[UIApplication sharedApplication] delegate] window].rootViewController=nav;
        }
    }];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
